package com.yifeng.repo.controller.statemachine.fsm.account;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by daibing on 2024/9/21.
 */
@Getter
@AllArgsConstructor
public enum AccountStateEnum {
    NOT_EXISTS("NOT_EXISTS", "账户不存在"),
    EXISTS_NOT_ACTIVED("NOT_ACTIVED", "账户已经存在但是尚未激活"),
    EXISTS_ACTIVED("ACTIVED", "账户已经存在并激活"),
    EXISTS_FROZEND("FROZEND", "账户已经存在并被冻结"),
    EXISTS_CLOSED("CLOSED", "账户已经存在并被销户");

    @EnumValue
    @JsonValue
    private final String code;

    private final String name;

    private static final Map<String, AccountStateEnum> mappings = new HashMap<>(8);

    static {
        for (AccountStateEnum value : values()) {
            mappings.put(value.getCode(), value);
        }
    }

    public static AccountStateEnum resolve(String code) {
        return (code != null ? mappings.get(code) : null);
    }
}
